//
//  TVStatementMonthsCell.swift
//  iPhone
//
//  Created by Toj on 11/16/22.
//

import UIKit

class TVStatementMonthsCell: UICollectionViewCell {
    
    var cellModel: TVStatementMonthCellModel? { didSet {
        guard let model = cellModel else { return }
        yearLabel.text = model.year
        monthLabel.text = model.month
        
        let color = model.isSelected ? "#E8CD8C".to_color : .white
        
        monthLabel.textColor = color
        yearLabel.textColor = color
    } }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupMakeAddSubviews()
        contentView.backgroundColor = "#222527".to_color
        contentView.cm_cornerRadius = 4
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        setupMakeLayoutSubviews()
    }
    
    private lazy var monthLabel: UILabel = {
        let view = UILabel()
        view.font = 12.to_boldFont
        return view
    }()
    
    private lazy var yearLabel: UILabel = {
        let view = UILabel()
        view.font = 10.to_systemFont
        return view
    }()
}

// MARK: - 初始化
extension TVStatementMonthsCell {
    
    private func setupMakeAddSubviews() {
        
        contentView.addSubview(monthLabel)
        contentView.addSubview(yearLabel)
    }
    
    private func setupMakeLayoutSubviews() {
        monthLabel.snp.makeConstraints { make in
            make.centerX.equalTo(contentView)
            make.bottom.equalTo(contentView.snp.centerY)
        }
        
        yearLabel.snp.makeConstraints { make in
            make.centerX.equalTo(contentView)
            make.top.equalTo(contentView.snp.centerY)
        }
    }
}
